<?php
/*
+-----------------------------------------------------------------------------+
| $Id: *.php 2009-08-18 08:41:22Z Bleakwind $
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
+-----------------------------------------------------------------------------+
*/

if (!defined( 'ENTRY_INDEX')){
    echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
    exit;
}

// topic_show_ip
function show_ip($id, $post_id)
{
    global $SETTING,$LANGUAGE,$MEMBER,$ADMIN,$select_option,$db;
    $ajax_response = new xajaxResponse();
    $ajax_response->assign($id, "innerHTML", "<img src=\"".$SETTING['dir_images']."/loading.gif\" border=\"0\" align=\"absmiddle\" />");
    $sql = "SELECT post.post_ip, member_group.mg_ag_id
            FROM ".DB_TABLE_POST." post
                LEFT JOIN ".DB_TABLE_MEMBER." member ON member.id=post.post_mid
                LEFT JOIN ".DB_TABLE_MEMBER_GROUP." member_group ON member_group.mg_type=member.mg_type
                    AND (member_group.mg_point_begin<=member.point || member_group.mg_point_begin IS NULL)
                    AND (member_group.mg_point_end>=member.point || member_group.mg_point_end IS NULL)
            WHERE post.id=".$post_id."";
    $result = &$db->Execute($sql);
    if (!$result) {
        $ajax_response->alert($LANGUAGE['s']['topic']['show_ip_db_select_error'].$sql);
    } else {
        if (!$result->EOF) {
            if ($ADMIN['ag_privilege']['viewip_post'] == "1"  && ($result->fields['mg_ag_id'] == "0" || ($result->fields['mg_ag_id'] > "0" && $ADMIN['ag_privilege']['admin_manage'] == "1")) ) {
                if (!empty($result->fields['post_ip'])) {
                    $ajax_response->assign($id, "innerHTML", "<span class=\"block_salient\">".$result->fields['post_ip']."</span>");
                } else {
                    $ajax_response->assign($id, "innerHTML", "");
                    $ajax_response->alert($LANGUAGE['s']['topic']['show_ip_db_select_error']);
                }
            } else {
                $ajax_response->assign($id, "innerHTML", "");
                $ajax_response->alert($LANGUAGE['s']['topic']['show_ip_manage_admin_no']);
            }
        }
    }
    return $ajax_response;
}
$bwajax->register(XAJAX_FUNCTION, "show_ip");

if( !preg_match("/^[1-9][0-9]{0,18}$/",$sys->get['topic_id']) ){
    $sys->prompt("failed",$LANGUAGE['s']['topic']['topic_id_error']."<!-- topic_id error -->");
} else {
    if ($ADMIN['ag_privilege']['topic'] == "1" || ($ADMIN['ag_privilege']['topic'] == "3" && $channel_info['channel_manage_admin_id'] != "")) {
        $ag_privilege_topic = "1";
    } else {
        $ag_privilege_topic = "2";
    }
    $sql = "SELECT topic.*,

                    icon_topic.filename as icon_filename,

                    post.id as post_id,
                    post.topic_id as post_topic_id,
                    post.content as post_content,
                    post.quote_id as post_quote_id,
                    post.quote_path as post_quote_path,
                    post.post_mid as post_post_mid,
                    post.post_musername as post_post_musername,
                    post.post_ip as post_post_ip,
                    post.post_time as post_post_time,
                    post.modify_mid as post_modify_mid,
                    post.modify_musername as post_modify_musername,
                    post.modify_ip as post_modify_ip,
                    post.modify_time as post_modify_time,
                    post.if_face as post_if_face,
                    post.if_face as post_if_face,
                    post.if_bbcode as post_if_bbcode,
                    post.if_url as post_if_url,
                    post.if_html as post_if_html,
                    post.floor as post_floor,
                    post.rank as post_rank,

                    channel.id as channel_id,
                    channel.name as channel_name,

                    member.id as m_id,
                    member.username as m_username,
                    member.email as m_email,
                    member.card as m_card,
                    member.mg_type as m_mg_type,
                    member.mg_type_expired as m_mg_type_expired,
                    member.silver as m_silver,
                    member.point as m_point,
                    member.bonus as m_bonus,
                    member.pile1 as m_pile1,
                    member.pile2 as m_pile2,
                    member.pile3 as m_pile3,
                    member.pile4 as m_pile4,
                    member.pile5 as m_pile5,
                    member.pile6 as m_pile6,
                    member.time_created as m_time_created,
                    member.time_lastvisit as m_time_lastvisit,
                    member.cumulant_silver as m_cumulant_silver,
                    member.cumulant_offer as m_cumulant_offer,
                    member.cumulant_online as m_cumulant_online,

                    member_detail.mid as md_mid,
                    member_detail.realname as md_realname,
                    member_detail.gender as md_gender,
                    member_detail.birthday as md_birthday,
                    member_detail.address as md_address,
                    member_detail.postalcode as md_postalcode,
                    member_detail.telephone as md_telephone,
                    member_detail.mobile as md_mobile,
                    member_detail.avatar_type as md_avatar_type,
                    member_detail.avatar_value as md_avatar_value,
                    member_detail.website as md_website,
                    member_detail.gtalk as md_gtalk,
                    member_detail.msn as md_msn,
                    member_detail.icq as md_icq,
                    member_detail.qq as md_qq,
                    member_detail.yahoo as md_yahoo,
                    member_detail.bio as md_bio,
                    member_detail.sign as md_sign,
                    member_detail.last_post as md_last_post,
                    member_detail.total_topic as md_total_topic,
                    member_detail.total_reply as md_total_reply,
                    member_detail.total_elite as md_total_elite,
                    member_detail.remark as md_remark,

                    member_group.mg_id,
                    member_group.mg_name,
                    member_group.mg_ag_id,
                    member_group.mg_privilege

            FROM ".DB_TABLE_TOPIC." topic
                LEFT JOIN ".DB_TABLE_ICON_TOPIC." icon_topic ON icon_topic.id=topic.icon
                LEFT JOIN ".DB_TABLE_POST." post ON post.id=topic.post_pid
                LEFT JOIN ".DB_TABLE_CHANNEL." channel ON channel.id=topic.channel_id
                LEFT JOIN ".DB_TABLE_MEMBER." member ON member.id=post.post_mid
                LEFT JOIN ".DB_TABLE_MEMBER_DETAIL." member_detail ON member_detail.mid=member.id
                LEFT JOIN ".DB_TABLE_MEMBER_GROUP." member_group ON member_group.mg_type=member.mg_type
                    AND (member_group.mg_point_begin<=member.point || member_group.mg_point_begin IS NULL)
                    AND (member_group.mg_point_end>=member.point || member_group.mg_point_end IS NULL)
            WHERE topic.id=".$sys->get['topic_id']."";
    $result = &$db->Execute($sql);
    if (!$result) {
        echo $db->ErrorMsg();
    } else {
        if (!$result->EOF) {
            if( preg_match("/^[1-9][0-9]{0,18}$/",$result->fields['post_quote_id']) && !empty($result->fields['post_quote_path']) ){
                $quote_list = func::db_select(DB_TABLE_POST, "id, topic_id, content, post_mid, post_musername, post_time, modify_mid, modify_musername, modify_time", "id IN (".$result->fields['post_quote_path'].")");
            } else {
                $quote_list = null;
            }
            $attach_list = func::db_select(DB_TABLE_POST_ATTACH, "*", "post_id=".$result->fields['post_pid'], "", "id DESC");
            $topic_info = array(
                    'id'                        => $result->fields['id'],
                    'channel_id'                => $result->fields['channel_id'],
                    'icon'                      => $result->fields['icon'],
                    'subject'                   => $result->fields['subject'],
                    'subject_len'               => mb_strwidth($result->fields['subject'],"UTF-8"),
                    'post_time'                 => $result->fields['post_time'],
                    'post_mid'                  => $result->fields['post_mid'],
                    'post_musername'            => $result->fields['post_musername'],
                    'post_ip'                   => $result->fields['post_ip'],
                    'post_pid'                  => $result->fields['post_pid'],
                    'number_reply'              => $result->fields['number_reply'],
                    'number_click'              => $result->fields['number_click'],
                    'last_time'                 => $result->fields['last_time'],
                    'last_mid'                  => $result->fields['last_mid'],
                    'last_musername'            => $result->fields['last_musername'],
                    'last_pid'                  => $result->fields['last_pid'],
                    'style_color'               => $result->fields['style_color'],
                    'style_fontstyle'           => $result->fields['style_fontstyle'],
                    'style_decoration'          => $result->fields['style_decoration'],
                    'style_begin'               => $result->fields['style_begin'],
                    'style_end'                 => $result->fields['style_end'],
                    'if_elite'                  => $result->fields['if_elite'],
                    'if_elite_begin'            => $result->fields['if_elite_begin'],
                    'if_elite_end'              => $result->fields['if_elite_end'],
                    'if_top'                    => $result->fields['if_top'],
                    'if_top_begin'              => $result->fields['if_top_begin'],
                    'if_top_end'                => $result->fields['if_top_end'],
                    'if_close'                  => $result->fields['if_close'],
                    'if_close_begin'            => $result->fields['if_close_begin'],
                    'if_close_end'              => $result->fields['if_close_end'],
                    'if_move'                   => $result->fields['if_move'],
                    'if_move_id'                => $result->fields['if_move_id'],
                    'if_del'                    => $result->fields['if_del'],
                    'rank'                      => $result->fields['rank'],

                    'icon_filename'             => $result->fields['icon_filename'],

                    'post_id'                   => $result->fields['post_id'],
                    'post_topic_id'             => $result->fields['post_topic_id'],
                    'post_content'              => $result->fields['post_content'],
                    'post_quote_id'             => $result->fields['post_quote_id'],
                    'post_quote_path'           => $result->fields['post_quote_path'],
                    'post_quote_list'           => $quote_list,
                    'post_post_mid'             => $result->fields['post_post_mid'],
                    'post_post_musername'       => $result->fields['post_post_musername'],
                    'post_post_ip'              => $result->fields['post_post_ip'],
                    'post_post_time'            => $result->fields['post_post_time'],
                    'post_modify_mid'           => $result->fields['post_modify_mid'],
                    'post_modify_musername'     => $result->fields['post_modify_musername'],
                    'post_modify_ip'            => $result->fields['post_modify_ip'],
                    'post_modify_time'          => $result->fields['post_modify_time'],
                    'post_if_face'              => $result->fields['post_if_face'],
                    'post_if_bbcode'            => $result->fields['post_if_bbcode'],
                    'post_if_url'               => $result->fields['post_if_url'],
                    'post_if_html'              => $result->fields['post_if_html'],
                    'post_floor'                => $result->fields['post_floor'],
                    'post_rank'                 => $result->fields['post_rank'],

                    'channel_id'                => $result->fields['channel_id'],
                    'channel_name'              => $result->fields['channel_name'],
                    'channel_name_len'          => mb_strwidth($result->fields['channel_name'],"UTF-8"),

                    'm_id'                      => $result->fields['m_id'],
                    'm_username'                => $result->fields['m_username'],
                    'm_email'                   => $result->fields['m_email'],
                    'm_card'                    => $result->fields['m_card'],
                    'm_mg_type'                 => $result->fields['m_mg_type'],
                    'm_mg_type_expired' => $result->fields['m_mg_type_expired'],
                    'm_silver'                  => $result->fields['m_silver'],
                    'm_point'                   => $result->fields['m_point'],
                    'm_bonus'                   => $result->fields['m_bonus'],
                    'm_pile1'                   => $result->fields['m_pile1'],
                    'm_pile2'                   => $result->fields['m_pile2'],
                    'm_pile3'                   => $result->fields['m_pile3'],
                    'm_pile4'                   => $result->fields['m_pile4'],
                    'm_pile5'                   => $result->fields['m_pile5'],
                    'm_pile6'                   => $result->fields['m_pile6'],
                    'm_time_created'            => $result->fields['m_time_created'],
                    'm_time_lastvisit'          => $result->fields['m_time_lastvisit'],
                    'm_cumulant_silver'         => $result->fields['m_cumulant_silver'],
                    'm_cumulant_offer'          => $result->fields['m_cumulant_offer'],
                    'm_cumulant_online'         => $result->fields['m_cumulant_online'],

                    'md_mid'                    => $result->fields['md_mid'],
                    'md_realname'               => $result->fields['md_realname'],
                    'md_gender'                 => $result->fields['md_gender'],
                    'md_birthday'               => $result->fields['md_birthday'],
                    'md_address'                => $result->fields['md_address'],
                    'md_postalcode'             => $result->fields['md_postalcode'],
                    'md_telephone'              => $result->fields['md_telephone'],
                    'md_mobile'                 => $result->fields['md_mobile'],
                    'md_avatar_type'            => $result->fields['md_avatar_type'],
                    'md_avatar_value'           => $result->fields['md_avatar_value'],
                    'md_website'                => $result->fields['md_website'],
                    'md_gtalk'                  => $result->fields['md_gtalk'],
                    'md_msn'                    => $result->fields['md_msn'],
                    'md_icq'                    => $result->fields['md_icq'],
                    'md_qq'                     => $result->fields['md_qq'],
                    'md_yahoo'                  => $result->fields['md_yahoo'],
                    'md_bio'                    => $result->fields['md_bio'],
                    'md_sign'                   => $result->fields['md_sign'],
                    'md_last_post'              => $result->fields['md_last_post'],
                    'md_total_topic'            => $result->fields['md_total_topic'],
                    'md_total_reply'            => $result->fields['md_total_reply'],
                    'md_total_elite'            => $result->fields['md_total_elite'],
                    'md_remark'                 => $result->fields['md_remark'],

                    'mg_id'                     => $result->fields['mg_id'],
                    'mg_name'                   => $result->fields['mg_name'],
                    'mg_ag_id'                  => $result->fields['mg_ag_id'],
                    'mg_privilege'              => unserialize($result->fields['mg_privilege']),

                    'attach_list'               => $attach_list,
            );
            if ($topic_info['m_mg_type_expired'] > 0) {
                if ($sys->check_member_group($topic_info['m_id'], $topic_info['m_mg_type_expired'])) {
                    $topic_info['m_mg_type']                  = $CONFIG['default_group_member'];
                    $topic_info['m_mg_type_expired']  = 0;
                    $this_member_group = $sys->return_member_group($topic_info['m_mg_type'], $topic_info['m_point'], "mg_id,mg_name,mg_privilege");
                    $topic_info['mg_id']                    = $this_member_group['mg_id'];
                    $topic_info['mg_name']                  = $this_member_group['mg_name'];
                    $topic_info['mg_privilege']             = unserialize($this_member_group['mg_privilege']);
                }
            }
        }
    }

    if( !preg_match("/^[1-9][0-9]{0,18}$/",$topic_info['id']) ){
        $sys->prompt("failed",$LANGUAGE['s']['topic']['topic_id_not_exist']."<!-- topic_id not exist -->");
    } elseif ($topic_info['if_del'] == "1") {
        $sys->prompt("failed",$LANGUAGE['s']['topic']['topic_id_already_del']."<!-- topic_id already del -->");
    } else {
        if ($topic_info['channel_id'] > 0) {
            $sys->return_channel_current($topic_info['channel_id']);
        }

        $channel_info   = $sys->return_channel_info($topic_info['channel_id']);
        $trans_value    = $sys->return_trans_value($topic_info['channel_id'], $topic_info['id']);
        $total_post     = func::db_count_record(DB_TABLE_POST, "topic_id=".$topic_info['id']);

        if ($sys->get['ope'] == "elite") {
            if ($ag_privilege_topic != "1") {
                $sys->prompt("failed",$LANGUAGE['s']['topic']['elite_ag_privilege_error']."<!-- elite_ag_privilege_error -->");
            } else {
                // topic_elite
                function topic_elite($value, $button_submit)
                {
                    global $SETTING,$LANGUAGE,$CONFIG,$CONFIGURE,$SESSION,$PROMPT,$MEMBER,$db,$sys,$c,$trans_value,$channel_info,$topic_info,$post_info,$icon_topic_list,$channel_tree,$ag_privilege_topic;
                    $ajax_response = new xajaxResponse();
                    $error = false;

                    if ($ag_privilege_topic != "1") {
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['elite_ag_privilege_error'];
                    } elseif( !preg_match("/^(19|20)[0-9]{2}-(0[1-9]{1}|1[0-2]{1})-(0[1-9]{1}|[1-2][0-9]{1}|3[0-1]{1})$/",$value['if_elite_begin'])
                              && $value['if_elite_begin'] != "0"){
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['elite_begin_error'];
                    } elseif( !preg_match("/^(19|20)[0-9]{2}-(0[1-9]{1}|1[0-2]{1})-(0[1-9]{1}|[1-2][0-9]{1}|3[0-1]{1})$/",$value['if_elite_end'])
                              && $value['if_elite_end'] != "0"){
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['elite_end_error'];
                    }
                    if($error){
                        $ajax_response->alert($error_msg);
                        $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_elite_submit']);
                        $ajax_response->assign($button_submit,"disabled",false);
                    }else{
                        $value['if_elite_begin']    = $value['if_elite_begin'] == "0" ? "0" : strtotime($value['if_elite_begin']);
                        $value['if_elite_end']      = $value['if_elite_end']   == "0" ? "0" : strtotime($value['if_elite_end']);
                        $value['if_elite']          = $value['if_elite_begin'] == "0" && $value['if_elite_end'] == "0" ? "1" : "3";
                        $sql_data = array(
                            "if_elite"          => (int)$value['if_elite'],
                            "if_elite_begin"    => (int)$value['if_elite_begin'],
                            "if_elite_end"      => (int)$value['if_elite_end'],
                        );
                        $result = func::db_update(DB_TABLE_TOPIC, $sql_data, "id='".$sys->get['topic_id']."'");
                        if (!$result) {
                            $error      = true;
                            $error_msg  = $LANGUAGE['s']['topic']['elite_topic_update_error'];
                        }

                        if ((int)$topic_info['m_point'] > (int)$CONFIG['point_group']['point_min']) {
                            $sql_data = array(
                                "point"           => "point+".(int)$CONFIG['point_group']['topic_elite'],
                            );
                            $result = func::db_update(DB_TABLE_MEMBER, $sql_data, "id=".(int)$topic_info['m_id']."");
                            if (!$result) {
                                $ajax_response->alert($LANGUAGE['s']['post']['update_member_point_topic_elite_error']);
                            }
                        }
                        if($error){
                            $ajax_response->alert($error_msg);
                            $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_elite_submit']);
                            $ajax_response->assign($button_submit,"disabled",false);
                        }else{
                            $ajax_response->redirect($CONFIGURE['common']['control_index']."?act=topic&topic_id=".$topic_info['id']);
                        }
                    }
                    return $ajax_response;
                }
                $bwajax->register(XAJAX_FUNCTION, "topic_elite");
            }

        } elseif ($sys->get['ope'] == "top") {
            if ($ag_privilege_topic != "1") {
                $sys->prompt("failed",$LANGUAGE['s']['topic']['top_ag_privilege_error']."<!-- top_ag_privilege_error -->");
            } else {
                // topic_top
                function topic_top($value, $button_submit)
                {
                    global $SETTING,$LANGUAGE,$CONFIG,$CONFIGURE,$SESSION,$PROMPT,$MEMBER,$db,$sys,$c,$trans_value,$channel_info,$topic_info,$post_info,$icon_topic_list,$channel_tree,$ag_privilege_topic;
                    $ajax_response = new xajaxResponse();
                    $error = false;

                    if ($ag_privilege_topic != "1") {
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['top_ag_privilege_error'];
                    } elseif( !preg_match("/^(19|20)[0-9]{2}-(0[1-9]{1}|1[0-2]{1})-(0[1-9]{1}|[1-2][0-9]{1}|3[0-1]{1})$/",$value['if_top_begin'])
                              && $value['if_top_begin'] != "0"){
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['top_begin_error'];
                    } elseif( !preg_match("/^(19|20)[0-9]{2}-(0[1-9]{1}|1[0-2]{1})-(0[1-9]{1}|[1-2][0-9]{1}|3[0-1]{1})$/",$value['if_top_end'])
                              && $value['if_top_end'] != "0"){
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['top_end_error'];
                    }
                    if($error){
                        $ajax_response->alert($error_msg);
                        $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_top_submit']);
                        $ajax_response->assign($button_submit,"disabled",false);
                    }else{
                        $value['if_top_begin']  = $value['if_top_begin'] == "0" ? "0" : strtotime($value['if_top_begin']);
                        $value['if_top_end']    = $value['if_top_end']   == "0" ? "0" : strtotime($value['if_top_end']);
                        $value['if_top']        = $value['if_top_begin'] == "0" && $value['if_top_end'] == "0" ? "1" : "3";
                        $sql_data = array(
                            "if_top" => (int)$value['if_top'],
                            "if_top_begin" => (int)$value['if_top_begin'],
                            "if_top_end" => (int)$value['if_top_end'],
                        );
                        $result = func::db_update(DB_TABLE_TOPIC, $sql_data, "id='".$sys->get['topic_id']."'");
                        if (!$result) {
                            $error      = true;
                            $error_msg  = $LANGUAGE['s']['topic']['top_topic_update_error'];
                        }

                        if ((int)$topic_info['m_point'] > (int)$CONFIG['point_group']['point_min']) {
                            $sql_data = array(
                                "point"           => "point+".(int)$CONFIG['point_group']['topic_top'],
                            );
                            $result = func::db_update(DB_TABLE_MEMBER, $sql_data, "id=".(int)$topic_info['m_id']."");
                            if (!$result) {
                                $ajax_response->alert($LANGUAGE['s']['post']['update_member_point_topic_top_error']);
                            }
                        }
                        if($error){
                            $ajax_response->alert($error_msg);
                            $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_top_submit']);
                            $ajax_response->assign($button_submit,"disabled",false);
                        }else{
                            $ajax_response->redirect($CONFIGURE['common']['control_index']."?act=topic&topic_id=".$topic_info['id']);
                        }
                    }
                    return $ajax_response;
                }
                $bwajax->register(XAJAX_FUNCTION, "topic_top");
            }

        } elseif ($sys->get['ope'] == "close") {
            if ($ag_privilege_topic != "1") {
                $sys->prompt("failed",$LANGUAGE['s']['topic']['close_ag_privilege_error']."<!-- close_ag_privilege_error -->");
            } else {
                // topic_close
                function topic_close($value, $button_submit)
                {
                    global $SETTING,$LANGUAGE,$CONFIG,$CONFIGURE,$SESSION,$PROMPT,$MEMBER,$db,$sys,$c,$trans_value,$channel_info,$topic_info,$post_info,$icon_topic_list,$channel_tree,$ag_privilege_topic;
                    $ajax_response = new xajaxResponse();
                    $error = false;

                    if ($ag_privilege_topic != "1") {
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['close_ag_privilege_error'];
                    } elseif( !preg_match("/^(19|20)[0-9]{2}-(0[1-9]{1}|1[0-2]{1})-(0[1-9]{1}|[1-2][0-9]{1}|3[0-1]{1})$/",$value['if_close_begin'])
                              && $value['if_close_begin'] != "0"){
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['close_begin_error'];
                    } elseif( !preg_match("/^(19|20)[0-9]{2}-(0[1-9]{1}|1[0-2]{1})-(0[1-9]{1}|[1-2][0-9]{1}|3[0-1]{1})$/",$value['if_close_end'])
                              && $value['if_close_end'] != "0"){
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['close_end_error'];
                    }
                    if($error){
                        $ajax_response->alert($error_msg);
                        $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_close_submit']);
                        $ajax_response->assign($button_submit,"disabled",false);
                    }else{
                        $value['if_close_begin']    = $value['if_close_begin'] == "0" ? "0" : strtotime($value['if_close_begin']);
                        $value['if_close_end']      = $value['if_close_end']   == "0" ? "0" : strtotime($value['if_close_end']);
                        $value['if_close']          = $value['if_close_begin'] == "0" && $value['if_close_end'] == "0" ? "1" : "3";
                        $sql_data = array(
                            "if_close" => (int)$value['if_close'],
                            "if_close_begin" => (int)$value['if_close_begin'],
                            "if_close_end" => (int)$value['if_close_end'],
                        );
                        $result = func::db_update(DB_TABLE_TOPIC, $sql_data, "id='".$sys->get['topic_id']."'");
                        if (!$result) {
                            $error      = true;
                            $error_msg  = $LANGUAGE['s']['topic']['close_topic_update_error'];
                        }

                        if ((int)$topic_info['m_point'] > (int)$CONFIG['point_group']['point_min']) {
                            $sql_data = array(
                                "point"           => "point+".(int)$CONFIG['point_group']['topic_close'],
                            );
                            $result = func::db_update(DB_TABLE_MEMBER, $sql_data, "id=".(int)$topic_info['m_id']."");
                            if (!$result) {
                                $ajax_response->alert($LANGUAGE['s']['post']['update_member_point_topic_close_error']);
                            }
                        }
                        if($error){
                            $ajax_response->alert($error_msg);
                            $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_close_submit']);
                            $ajax_response->assign($button_submit,"disabled",false);
                        }else{
                            $ajax_response->redirect($CONFIGURE['common']['control_index']."?act=topic&topic_id=".$topic_info['id']);
                        }
                    }
                    return $ajax_response;
                }
                $bwajax->register(XAJAX_FUNCTION, "topic_close");
            }

        } elseif ($sys->get['ope'] == "move") {
            if ($ag_privilege_topic != "1") {
                $sys->prompt("failed",$LANGUAGE['s']['topic']['move_ag_privilege_error']."<!-- move_ag_privilege_error -->");
            } else {
                // topic_move
                function topic_move($value, $button_submit)
                {
                    global $SETTING,$LANGUAGE,$CONFIG,$CONFIGURE,$SESSION,$PROMPT,$MEMBER,$db,$sys,$c,$trans_value,$channel_info,$topic_info,$post_info,$icon_topic_list,$channel_tree,$ag_privilege_topic;
                    $ajax_response = new xajaxResponse();
                    $error = false;

                    if ($ag_privilege_topic != "1") {
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['move_ag_privilege_error'];
                    } elseif( !preg_match("/^[1-9][0-9]{0,18}$/",$value['channel_tree_to']) ){
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['move_channel_tree_to_error'];
                    }
                    if($error){
                        $ajax_response->alert($error_msg);
                        $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_move_submit']);
                        $ajax_response->assign($button_submit,"disabled",false);
                    }else{
                        $sql_data = array(
                            "channel_id" => $value['channel_tree_to'],
                        );
                        $result = func::db_update(DB_TABLE_TOPIC, $sql_data, "id='".$sys->get['topic_id']."'");
                        if (!$result) {
                            $error      = true;
                            $error_msg  = $LANGUAGE['s']['topic']['move_topic_update_error'];
                        }
                        if ((int)$topic_info['m_point'] > (int)$CONFIG['point_group']['point_min']) {
                            $sql_data = array(
                                "point"           => "point+".(int)$CONFIG['point_group']['topic_move'],
                            );
                            $result = func::db_update(DB_TABLE_MEMBER, $sql_data, "id=".(int)$topic_info['m_id']."");
                            if (!$result) {
                                $ajax_response->alert($LANGUAGE['s']['post']['update_member_point_topic_move_error']);
                            }
                        }
                        $sql_data = array(
                            "number_total_topic"        => "number_total_topic-1",
                            "number_total_post"         => "number_total_post-".($topic_info['number_reply']+1)."",
                            "number_today_topic"        => "number_today_topic-1",
                            "number_today_post"         => "number_today_post-".($topic_info['number_reply']+1)."",
                        );
                        $result = func::db_update(DB_TABLE_CHANNEL, $sql_data, "id=".(int)$topic_info['channel_id']."");
                        if (!$result) {
                            $ajax_response->alert($LANGUAGE['s']['topic']['move_channel_number_error']);
                        }
                        $sql_data = array(
                            "number_total_topic"        => "number_total_topic+1",
                            "number_total_post"         => "number_total_post+".($topic_info['number_reply']+1)."",
                            "number_today_topic"        => "number_today_topic+1",
                            "number_today_post"         => "number_today_post+".($topic_info['number_reply']+1)."",
                        );
                        $result = func::db_update(DB_TABLE_CHANNEL, $sql_data, "id=".(int)$value['channel_tree_to']."");
                        if (!$result) {
                            $ajax_response->alert($LANGUAGE['s']['topic']['move_channel_number_error']);
                        }
                        if ( !$sys->update_channel_last((int)$topic_info['channel_id']) ) {
                            $ajax_response->alert($LANGUAGE['s']['topic']['move_channel_last_error']);
                        }
                        if ( !$sys->update_channel_last((int)$value['channel_tree_to']) ) {
                            $ajax_response->alert($LANGUAGE['s']['topic']['move_channel_last_error']);
                        }
                        if($error){
                            $ajax_response->alert($error_msg);
                            $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_move_submit']);
                            $ajax_response->assign($button_submit,"disabled",false);
                        }else{
                            $ajax_response->redirect($CONFIGURE['common']['control_index']."?act=channel&channel_id=".$topic_info['channel_id']);
                        }
                    }
                    return $ajax_response;
                }
                $bwajax->register(XAJAX_FUNCTION, "topic_move");
            }

        } elseif ($sys->get['ope'] == "del") {
            if ($ag_privilege_topic != "1") {
                $sys->prompt("failed",$LANGUAGE['s']['topic']['del_ag_privilege_error']."<!-- del_ag_privilege_error -->");
            } else {
                // topic_del
                function topic_del($value, $button_submit)
                {
                    global $SETTING,$LANGUAGE,$CONFIG,$CONFIGURE,$SESSION,$PROMPT,$MEMBER,$db,$sys,$c,$trans_value,$channel_info,$topic_info,$post_info,$icon_topic_list,$ag_privilege_topic;
                    $ajax_response = new xajaxResponse();
                    $error = false;

                    if ($ag_privilege_topic != "1") {
                        $error      = true;
                        $error_msg  = $LANGUAGE['s']['topic']['del_ag_privilege_error'];
                    }
                    if($error){
                        $ajax_response->alert($error_msg);
                        $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_del_submit']);
                        $ajax_response->assign($button_submit,"disabled",false);
                    }else{
                        $result = func::db_delete(DB_TABLE_TOPIC, "id=".$topic_info['id']."");
                        if (!$result) {
                            $error      = true;
                            $error_msg  = $LANGUAGE['s']['topic']['del_topic_delete_error'];
                        } else {
                            $sql = "SELECT post_attach.*
                                    FROM ".DB_TABLE_POST_ATTACH." post_attach
                                        LEFT JOIN ".DB_TABLE_POST." post ON post.id=post_attach.post_id
                                    WHERE post.topic_id=".$topic_info['id']."
                                    ORDER BY id desc";
                            $result = &$db->Execute($sql);
                            if (!$result) {
                                $error      = true;
                                $error_msg  = $LANGUAGE['s']['topic']['del_post_attach_select_error'];
                            } else {
                                while (!$result->EOF) {
                                    $filelist[] = array(
                                        'id'        => $result->fields['id'],
                                        'dir'       => $result->fields['dir'],
                                        'filename'  => $result->fields['filename'],
                                        'post_id'   => $result->fields['post_id'],
                                        'admin_id'  => $result->fields['admin_id'],
                                    );
                                    $result->MoveNext();
                                }
                            }
                            if (!empty($filelist)){
                                foreach($filelist as $file){
                                    chmod($SETTING['dir_post_attach']."/".$file['dir']."/".$file['filename'], $SETTING['chmod_mode_file']);
                                    unlink($SETTING['dir_post_attach']."/".$file['dir']."/".$file['filename']);
                                }
                                $sql = "DELETE post_attach
                                        FROM ".DB_TABLE_POST_ATTACH." post_attach
                                            LEFT JOIN ".DB_TABLE_POST." post ON post.id=post_attach.post_id
                                        WHERE post.topic_id=".$topic_info['id'];
                                $result = &$db->Execute($sql);
                                if (!$result) {
                                    $error      = true;
                                    $error_msg  = $LANGUAGE['s']['topic']['del_post_attach_delete_error'];
                                }
                            }
                            $result = func::db_delete(DB_TABLE_TOPIC_TRANS, "topic_id=".$topic_info['id']."");
                            if (!$result) {
                                $error      = true;
                                $error_msg  = $LANGUAGE['s']['topic']['del_trans_delete_error'];
                            }
                            $sql_data = array(
                                "number_total_topic"        => "number_total_topic-1",
                                "number_total_post"         => "number_total_post-".($topic_info['number_reply']+1)."",
                                "number_today_topic"        => "number_today_topic-1",
                                "number_today_post"         => "number_today_post-".($topic_info['number_reply']+1)."",
                            );
                            $result = func::db_update(DB_TABLE_CHANNEL, $sql_data, "id=".(int)$topic_info['channel_id']."");
                            if (!$result) {
                                $ajax_response->alert($LANGUAGE['s']['topic']['del_channel_number_error']);
                            }
                            if ( !$sys->update_channel_last((int)$topic_info['channel_id']) ) {
                                $ajax_response->alert($LANGUAGE['s']['topic']['del_channel_last_error']);
                            }
                        }
                        if($error){
                            $ajax_response->alert($error_msg);
                            $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['topic_del_submit']);
                            $ajax_response->assign($button_submit,"disabled",false);
                        }else{
                            $ajax_response->redirect($CONFIGURE['common']['control_index']."?act=channel&channel_id=".$topic_info['channel_id']);
                        }
                    }
                    return $ajax_response;
                }
                $bwajax->register(XAJAX_FUNCTION, "topic_del");
            }

        } else {
            // Public ajax
            function submit_reply($value, $button_submit)
            {
                global $SETTING,$LANGUAGE,$CONFIG,$CONFIGURE,$SESSION,$PROMPT,$MEMBER,$db,$sys,$c,$trans_value,$channel_info,$topic_info,$post_info,$quote_path,$icon_topic_list;
                $ajax_response = new xajaxResponse();
                $error = false;
                //$ajax_response->alert(print_r($value, true)); $ajax_response->assign($button_submit,"disabled",false); return $ajax_response;

                // check the avatar
                if( $topic_info['if_close'] == 1 || ($topic_info['if_close'] == 3 && $topic_info['if_close_begin'] < $sys->nowtime && $topic_info['if_close_end'] > $sys->nowtime) ){
                    $error = true;
                    $ajax_response->alert($LANGUAGE['s']['topic']['topic_if_close_yes']);
                } elseif( $MEMBER['mg_privilege']['if_forbidpost'] == "1" && $ag_privilege_topic != "1" ){
                    $error = true;
                    $ajax_response->assign("content_return", "innerHTML", "<span class=\"prompt_failed\">".$LANGUAGE['s']['topic']['forbid_post']."</span>");
                } elseif (empty($value['content'])) {
                    $error = true;
                    $ajax_response->assign("content_return", "innerHTML", "<span class=\"prompt_failed\">".$LANGUAGE['s']['topic']['content_empty']."</span>");
                } elseif (mb_strlen($value['content'], "utf-8") > $CONFIG['max_reply_content']) {
                    $error = true;
                    $ajax_response->assign("content_return", "innerHTML", "<span class=\"prompt_failed\">".sprintf($LANGUAGE['s']['topic']['content_error'],$CONFIG['max_reply_content'])."</span>");
                } else {
                    $ajax_response->assign("content_return", "innerHTML", "");
                }

                if($error){
                    $ajax_response->assign($button_submit,"value",$LANGUAGE['s']['topic']['submit_reply']);
                    $ajax_response->assign($button_submit,"disabled",false);
                }else{

                    $config_list = func::db_select(DB_TABLE_CONFIG, "name,value", "name='censor_post'");
                    if (!empty($config_list)) {
                        foreach($config_list as $v){
                            $CONFIG[$v['name']] = trim($v['value']);
                        }
                    }
                    $str_search = preg_match_all('/(.*)=/i', $CONFIG['censor_post'], $matches);
                    $str_search = $matches[1];
                    $str_replace = preg_match_all('/=(.*)/i', $CONFIG['censor_post'], $matches);
                    $str_replace = $matches[1];
                    for($i=0; $size=count($str_search),$i<$size;$i++) {
                        $value['content'] = eregi_replace($str_search[$i], $str_replace[$i], $value['content']);
                    }

                    if ( $channel_info['if_face'] == "1" && $value['if_face'] == "1") {
                            $value['if_face'] = "1";
                    } else {
                            $value['if_face'] = "2";
                    }
                    if ( $channel_info['if_bbcode'] == "1" && $value['if_bbcode'] == "1") {
                            $value['if_bbcode'] = "1";
                    } else {
                            $value['if_bbcode'] = "2";
                    }
                    if ( $channel_info['if_url'] == "1" && $value['if_url'] == "1") {
                            $value['if_url'] = "1";
                    } else {
                            $value['if_url'] = "2";
                    }
                    if ( $channel_info['if_html'] == "1" && $value['if_html'] == "1") {
                            $value['if_html'] = "1";
                    } else {
                            $value['if_html'] = "2";
                    }
                    $sql = "INSERT INTO ".DB_TABLE_POST." SET
                                topic_id                = '".$topic_info['id']."',
                                content                 = '".addslashes($value['content'])."',
                                post_mid                = '".$MEMBER['id']."',
                                post_musername          = '".$MEMBER['username']."',
                                post_ip                 = '".func::return_ip()."',
                                post_time               = ".$sys->nowtime.",
                                modify_mid              = '0',
                                modify_musername       = '',
                                modify_ip               = '',
                                modify_time             = '0',
                                if_face                 = ".$value['if_face'].",
                                if_bbcode               = ".$value['if_bbcode'].",
                                if_url                  = ".$value['if_url'].",
                                if_html                 = ".$value['if_html'].",
                                floor                   = '0',
                                rank                    = ".$sys->nowtime."";
                    $result = $db->Execute($sql);
                    if (!$result) {
                        $ajax_response->alert($db->ErrorMsg());
                    }else{
                        $post_id = $db->Insert_ID();
                        $floor_last = func::db_select(DB_TABLE_POST, "floor", "topic_id=".$topic_info['id']." AND floor!=0", "1", "rank DESC,id DESC");
                        $floor_last =  $floor_last[0]['floor'];
                        $floor_update = func::db_select(DB_TABLE_POST, "id", "topic_id=".$topic_info['id']." AND floor=0", "", "rank,id");
                        if (!empty($floor_update)) {
                            foreach ($floor_update as $v) {
                                $sql_data = array(
                                    "floor" => $floor_last."+1",
                                );
                                $result = func::db_update(DB_TABLE_POST, $sql_data, "id=".(int)$v['id']."");
                                if (!$result) {
                                    $ajax_response->alert($LANGUAGE['s']['topic']['update_floor_error']);
                                }
                                $floor_last++;
                            }
                        }
                        $sql_data = array(
                            "last_mid"          => "".(int)$MEMBER['id']."",
                            "last_musername"    => "'".$MEMBER['username']."'",
                            "last_time"         => "".(int)$sys->nowtime."",
                            "last_pid"          => "".(int)$post_id."",
                            "number_reply"      => "number_reply+1",
                            "rank"              => "".$sys->nowtime."",
                        );
                        $result = func::db_update(DB_TABLE_TOPIC, $sql_data, "id=".(int)$topic_info['id']."");
                        if (!$result) {
                            $ajax_response->alert($LANGUAGE['s']['topic']['update_topic_error']);
                        }
                        $sql_data = array(
                            "number_total_post"         => "number_total_post+1",
                            "number_today_post"         => "number_today_post+1",
                            "last_post_id"              => "'".(int)$post_id."'",
                            "last_post_topic_id"        => "'".(int)$topic_info['id']."'",
                            "last_post_mid"             => "'".(int)$MEMBER['id']."'",
                            "last_post_musername"       => "'".$MEMBER['username']."'",
                            "last_post_time"            => "'".(int)$sys->nowtime."'",

                        );
                        $result = func::db_update(DB_TABLE_CHANNEL, $sql_data, "id=".(int)$topic_info['channel_id']."");
                        if (!$result) {
                            $ajax_response->alert($LANGUAGE['s']['topic']['update_channel_error']);
                        }

                        $sql_data = array(
                            "last_post"           => "'".(int)$post_id."'",
                            "total_reply"         => "total_reply+1",
                        );
                        $result = func::db_update(DB_TABLE_MEMBER_DETAIL, $sql_data, "mid=".(int)$MEMBER['id']."");
                        if (!$result) {
                            $ajax_response->alert($LANGUAGE['s']['topic']['update_member_detail_error']);
                        }

                        if ((int)$MEMBER['point'] > (int)$CONFIG['point_group']['point_min']) {
                            $sql_data = array(
                                "point"           => "point+".(int)$CONFIG['point_group']['topic_reply'],
                            );
                            $result = func::db_update(DB_TABLE_MEMBER, $sql_data, "id=".(int)$MEMBER['id']."");
                            if (!$result) {
                                $ajax_response->alert($LANGUAGE['s']['post']['update_member_point_topic_reply_error']);
                            }
                        }
                        $ajax_response->redirect($CONFIGURE['common']['control_index']."?act=topic&topic_id=".$topic_info['id']."&post_id=".$post_id."&#pid_".$post_id);
                    }
                }
                return $ajax_response;
            }
            $bwajax->register(XAJAX_FUNCTION, "submit_reply");

            // Begin get post
            if( preg_match("/^[1-9][0-9]{0,18}$/",$sys->get['post_id']) ){
                $redirect_record    = func::db_count_record(DB_TABLE_POST, "topic_id=".$topic_info['id']." AND id<=".$sys->get['post_id']);
                $page_current       = ceil($redirect_record/$CONFIG['page_record_post_list']);
                if( !preg_match("/^[1-9][0-9]{0,10}$/",$sys->get['pag']) ){
                    $bwpage->page_current   = $page_current;
                }
            }
            $record_pre             = $CONFIG['page_record_post_list'];
            $total_record           = $total_post;
            $bwpage->set_record_listnum($record_pre);
            $bwpage->set_record($total_record);
            $bwpage->page($CONFIGURE['common']['control_index']."?act=topic&topic_id=".$topic_info['id']."&pag=%s");
            $sql = "SELECT post.*,

                        member.id as m_id,
                        member.username as m_username,
                        member.email as m_email,
                        member.card as m_card,
                        member.mg_type as m_mg_type,
                        member.mg_type_expired as m_mg_type_expired,
                        member.silver as m_silver,
                        member.point as m_point,
                        member.bonus as m_bonus,
                        member.pile1 as m_pile1,
                        member.pile2 as m_pile2,
                        member.pile3 as m_pile3,
                        member.pile4 as m_pile4,
                        member.pile5 as m_pile5,
                        member.pile6 as m_pile6,
                        member.time_created as m_time_created,
                        member.time_lastvisit as m_time_lastvisit,
                        member.cumulant_silver as m_cumulant_silver,
                        member.cumulant_offer as m_cumulant_offer,
                        member.cumulant_online as m_cumulant_online,

                        member_detail.mid as md_mid,
                        member_detail.realname as md_realname,
                        member_detail.gender as md_gender,
                        member_detail.birthday as md_birthday,
                        member_detail.address as md_address,
                        member_detail.postalcode as md_postalcode,
                        member_detail.telephone as md_telephone,
                        member_detail.mobile as md_mobile,
                        member_detail.avatar_type as md_avatar_type,
                        member_detail.avatar_value as md_avatar_value,
                        member_detail.website as md_website,
                        member_detail.gtalk as md_gtalk,
                        member_detail.msn as md_msn,
                        member_detail.icq as md_icq,
                        member_detail.qq as md_qq,
                        member_detail.yahoo as md_yahoo,
                        member_detail.bio as md_bio,
                        member_detail.sign as md_sign,
                        member_detail.last_post as md_last_post,
                        member_detail.total_topic as md_total_topic,
                        member_detail.total_reply as md_total_reply,
                        member_detail.total_elite as md_total_elite,
                        member_detail.remark as md_remark,

                        member_group.mg_id,
                        member_group.mg_name,
                        member_group.mg_ag_id,
                        member_group.mg_privilege
                    FROM ".DB_TABLE_POST." post
                        LEFT JOIN ".DB_TABLE_MEMBER." member ON member.id=post.post_mid
                        LEFT JOIN ".DB_TABLE_MEMBER_DETAIL." member_detail ON member_detail.mid=member.id
                        LEFT JOIN ".DB_TABLE_MEMBER_GROUP." member_group ON member_group.mg_type=member.mg_type
                            AND (member_group.mg_point_begin<=member.point || member_group.mg_point_begin IS NULL)
                            AND (member_group.mg_point_end>=member.point || member_group.mg_point_end IS NULL)
                    WHERE topic_id=".$topic_info['id']."
                    ORDER BY post.rank, post.id DESC
                    LIMIT ".$bwpage->record_listfirst.",".$bwpage->record_listnum;
            $result = &$db->Execute($sql);
            if (!$result) {
                echo $db->ErrorMsg();
            } else {
                while (!$result->EOF) {
                    if( preg_match("/^[1-9][0-9]{0,18}$/",$result->fields['quote_id']) && !empty($result->fields['quote_path']) ){
                        $quote_list = func::db_select(DB_TABLE_POST, "id, topic_id, content, post_mid, post_musername, post_time, modify_mid, modify_musername, modify_time", "id IN (".$result->fields['quote_path'].")");
                    } else {
                        $quote_list = null;
                    }
                    $attach_list = func::db_select(DB_TABLE_POST_ATTACH, "*", "post_id=".$result->fields['id'], "", "id DESC");
                    $post_list[$result->fields['id']] = array(
                        'post_id'                   => $result->fields['id'],
                        'post_topic_id'             => $result->fields['topic_id'],
                        'post_content'              => $result->fields['content'],
                        'post_quote_id'             => $result->fields['quote_id'],
                        'post_quote_path'           => $result->fields['quote_path'],
                        'post_quote_list'           => $quote_list,
                        'post_post_mid'             => $result->fields['post_mid'],
                        'post_post_musername'       => $result->fields['post_musername'],
                        'post_post_ip'              => $result->fields['post_ip'],
                        'post_post_time'            => $result->fields['post_time'],
                        'post_modify_mid'           => $result->fields['modify_mid'],
                        'post_modify_musername'     => $result->fields['modify_musername'],
                        'post_modify_ip'            => $result->fields['modify_ip'],
                        'post_modify_time'          => $result->fields['modify_time'],
                        'post_if_face'              => $result->fields['if_face'],
                        'post_if_bbcode'            => $result->fields['if_bbcode'],
                        'post_if_url'               => $result->fields['if_url'],
                        'post_if_html'              => $result->fields['if_html'],
                        'post_floor'                => $result->fields['floor'],
                        'post_rank'                 => $result->fields['rank'],

                        'm_id'                      => $result->fields['m_id'],
                        'm_username'                => $result->fields['m_username'],
                        'm_email'                   => $result->fields['m_email'],
                        'm_card'                    => $result->fields['m_card'],
                        'm_mg_type'                 => $result->fields['m_mg_type'],
                        'm_mg_type_expired' => $result->fields['m_mg_type_expired'],
                        'm_silver'                  => $result->fields['m_silver'],
                        'm_point'                   => $result->fields['m_point'],
                        'm_bonus'                   => $result->fields['m_bonus'],
                        'm_pile1'                   => $result->fields['m_pile1'],
                        'm_pile2'                   => $result->fields['m_pile2'],
                        'm_pile3'                   => $result->fields['m_pile3'],
                        'm_pile4'                   => $result->fields['m_pile4'],
                        'm_pile5'                   => $result->fields['m_pile5'],
                        'm_pile6'                   => $result->fields['m_pile6'],
                        'm_time_created'            => $result->fields['m_time_created'],
                        'm_time_lastvisit'          => $result->fields['m_time_lastvisit'],
                        'm_cumulant_silver'         => $result->fields['m_cumulant_silver'],
                        'm_cumulant_offer'          => $result->fields['m_cumulant_offer'],
                        'm_cumulant_online'         => $result->fields['m_cumulant_online'],

                        'md_mid'                    => $result->fields['md_mid'],
                        'md_realname'               => $result->fields['md_realname'],
                        'md_gender'                 => $result->fields['md_gender'],
                        'md_birthday'               => $result->fields['md_birthday'],
                        'md_address'                => $result->fields['md_address'],
                        'md_postalcode'             => $result->fields['md_postalcode'],
                        'md_telephone'              => $result->fields['md_telephone'],
                        'md_mobile'                 => $result->fields['md_mobile'],
                        'md_avatar_type'            => $result->fields['md_avatar_type'],
                        'md_avatar_value'           => $result->fields['md_avatar_value'],
                        'md_website'                => $result->fields['md_website'],
                        'md_gtalk'                  => $result->fields['md_gtalk'],
                        'md_msn'                    => $result->fields['md_msn'],
                        'md_icq'                    => $result->fields['md_icq'],
                        'md_qq'                     => $result->fields['md_qq'],
                        'md_yahoo'                  => $result->fields['md_yahoo'],
                        'md_bio'                    => $result->fields['md_bio'],
                        'md_sign'                   => $result->fields['md_sign'],
                        'md_last_post'              => $result->fields['md_last_post'],
                        'md_total_topic'            => $result->fields['md_total_topic'],
                        'md_total_reply'            => $result->fields['md_total_reply'],
                        'md_total_elite'            => $result->fields['md_total_elite'],
                        'md_remark'                 => $result->fields['md_remark'],

                        'mg_id'                     => $result->fields['mg_id'],
                        'mg_name'                   => $result->fields['mg_name'],
                        'mg_ag_id'                  => $result->fields['mg_ag_id'],
                        'mg_privilege'              => unserialize($result->fields['mg_privilege']),

                        'attach_list'               => $attach_list,
                    );
                    $result->MoveNext();
                    if ($post_list[$result->fields['id']]['m_mg_type_expired'] > 0) {
                        if ($sys->check_member_group($post_list[$result->fields['id']]['m_id'], $post_list[$result->fields['id']]['m_mg_type_expired'])) {
                            $post_list[$result->fields['id']]['m_mg_type']                  = $CONFIG['default_group_member'];
                            $post_list[$result->fields['id']]['m_mg_type_expired']  = 0;
                            $this_member_group = $sys->return_member_group($post_list[$result->fields['id']]['m_mg_type'], $post_list[$result->fields['id']]['m_point'], "mg_id,mg_name,mg_privilege");
                            $post_list[$result->fields['id']]['mg_id']                      = $this_member_group['mg_id'];
                            $post_list[$result->fields['id']]['mg_name']                    = $this_member_group['mg_name'];
                            $post_list[$result->fields['id']]['mg_privilege']               = unserialize($this_member_group['mg_privilege']);
                        }
                    }
                }
            }
            $sql_data = array(
                "number_click" => "number_click+1",
            );
            $result = func::db_update(DB_TABLE_TOPIC, $sql_data, "id='".$topic_info['id']."'");
            if (!$result) {
                $sys->prompt("failed",$LANGUAGE['s']['topic']['update_topic_error']."<!-- update_topic_error -->");
            }
        }
        $t->assign(array(
            "topic_id"          => $topic_info['id'],
            "topic_info"        => $topic_info,
            "post_list"         => $post_list,
            "trans_value"       => $trans_value,
            "channel_info"      => $channel_info,
            "channel_current"   => $sys->channel_current,
            "total_post"        => $total_post,
            "pagination"        => $bwpage->pagination,
        ));
    }
}
if (!empty($sys->channel_current)) { 
    foreach($sys->channel_current as $v){
        $public_var['page_place'][] = $v['name'];
        $public_var['page_keyword'] = array_merge((array)$public_var['page_keyword'], array_filter(preg_split("/[\s,]+/", $v['keyword'])));
    }
}
$public_var['page_place'][] = $topic_info['subject'];
?>
